/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-12-10     xu       the first version
 */
#ifndef APPLICATIONS_HTTP_UTILS_H_
#define APPLICATIONS_HTTP_UTILS_H_

#include "cJSON.h"
#include <rtthread.h>

char* strdup_gbk(const char* str);

void parse_string_field(cJSON* json, const char* name, const char** value);

int append_string_field(cJSON* json, const char* name, const char* value);

int http_get(const char* uri, char** response, size_t* resp_len);

int http_down(const char* uri, const char* path);

#define SAFE_FREE(ptr)       \
    if (ptr) {               \
        rt_free((void*) ptr); \
    }

#endif /* APPLICATIONS_HTTP_UTILS_H_ */